from django.http.response import HttpResponse
from django.utils.deprecation import MiddlewareMixin

class Mymiddlewares(MiddlewareMixin):
    def __init__(self,get_response=None):
        super().__init__(get_response)
        print("init")  # 服务器启动或重启时执行

    def process_request(self,request):
        print("before 视图")
        # return HttpResponse("AAAA")

    def process_response(self, request, response):
        print('after 视图')
        return response

class Mymiddlewares2(MiddlewareMixin):
    def __init__(self,get_response=None):
        super().__init__(get_response)
        print("init2")  # 服务器启动或重启时执行

    def process_request(self,request):
        print("before2 视图")
        # return HttpResponse("AAAA")

    def process_response(self, request, response):
        print('after2 视图')
        return response